package com.llkj.qingnianguoxue.adapter;

import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.HotRankingBean;
import com.llkj.qingnianguoxue.util.DisplayUtil;
import com.llkj.qingnianguoxue.util.ImageLoadingUtil;

import java.util.List;

/**
 * 首页——精选视频书籍
 */
public class BookDetailRecommendAdapter extends BaseQuickAdapter<HotRankingBean.RankingBean,BaseViewHolder> {
    private int type = 1;//1视频，2书籍

    public BookDetailRecommendAdapter(int layoutResId, List<HotRankingBean.RankingBean> data) {
        super(layoutResId, data);
    }

    @Override
    public int getItemCount() {
        int count = 0;
        count = mData.size()>4?4:mData.size();
        return count;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, HotRankingBean.RankingBean item) {
        ImageView ivPic = baseViewHolder.getView(R.id.iv_video_pic);
        baseViewHolder.setText(R.id.tv_title, item.getTitle());
        baseViewHolder.setText(R.id.tv_price, "￥" + item.getPrice());

        ImageView ivVideoPlay = baseViewHolder.getView(R.id.iv_play);
        TextView tvTitle = baseViewHolder.getView(R.id.tv_title);

        TextView tvCatoryTag = baseViewHolder.getView(R.id.tvTag);
        tvCatoryTag.setVisibility(View.GONE);

        LinearLayout llRoot = baseViewHolder.getView(R.id.ll_root);
        LinearLayout.LayoutParams rootParams = (LinearLayout.LayoutParams) llRoot.getLayoutParams();
        FrameLayout.LayoutParams picParams = (FrameLayout.LayoutParams) ivPic.getLayoutParams();

        tvTitle.setMaxLines(1);
        ivVideoPlay.setVisibility(View.INVISIBLE);
        picParams.width = (DisplayUtil.getDensityWdith(mContext)-DisplayUtil.dip2px(mContext, 60))/4;
        picParams.height = picParams.width*14/13;

        rootParams.width = picParams.width;
        ImageLoadingUtil.loadImgGlideRoundCenterCrop(ivPic, item.getImg());
    }

    public void setType(int type1){
        type = type1;
    }
}
